//define(['js/module.js','jquery'],function(controllers,$){
    'use strict';
	angular.module('usercenter.billSettingList', [])
    .controller('billSettingListCtrl'
    		,['$rootScope', '$scope', '$state', 'BizData', '$uibModal', '$ocLazyLoad'
                                       ,f])
    function f($rootScope,$scope,$state,BizData,$uibModal,$ocLazyLoad
	                                		  ) {
		$scope.headerText = '----------我是系统客户区subsysListCtrl控制器！id为-->'+$scope.$id+'开始----------';
		$scope.footerText = '----------我是系统客户区subsysListCtrl控制器！id为-->'+$scope.$id+'结束----------';

		var Model = this;
		

		/**
		name:bizData#onBeforeDelete
		description: <b>[回调型事件]</b>业务数据删除前
		@param {object} event 它的结构如下:<br/>
		{
			"source":组件的js对象
			,"cancel":可修改	，设置为true后中断当前delete动作
			,"deleteIDList":删除的行Id数组
		}
		*/
		Model.dataBillSettingBeforeDelete = function(event) {
//			alert(event.deleteIDList[0]);
		}
		/**
		name:bizData#onAfterDelete
		description: <b>[回调型事件]</b>业务数据删除后
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"deleteIDList" : 删除的行Id数组
		}
		</xmp>	
		*/
		Model.dataBillSettingAfterDelete = function(event) {
//			alert('删除之后！')
		}



		
		
		/**
		name:bizData#onIndexChanged
		description: <b>[回调型事件]</b>行记录变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"rowID" : 行Id,
			"rowIndex" : 行索引
		}
		</xmp>	
		*/
		Model.dataBillSettingIndexChanged = function(event) {
			
		}
		
		/**
		name:bizData#onDataChanged
		description: <b>[回调型事件]</b>数据发生变化（包括新增、刷新、删除、修改引起的变化），感知从data的变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"changedSource" ：触发变化的组件的js对象，当从data触发时返回从data对象,
			"selfChanged" : 是否自身变化，false：从data触发的变化,
			"type" : 触发变化的类型，包括：new、delete、refresh、valueChanged、clear，其他参数根据触发类型不同给出不同参数，参考onAfterNew等事件参数
		}
		</xmp>	
		*/
		Model.dataBillSettingDataChanged = function(event) {
			
		}
		
		/**
		name:bizData#onValueChanged
		description: <b>[回调型事件]</b>数据变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"column" : 关系,
			"rowIndex" : 行索引,
			"value" : 新值,
			"originalValue" : 旧值
		}
		</xmp>	
		*/
		//输入值变化，监视input的输入，ng-change
		Model.dataBillSettingValueChanged = function(event) {

		}
		

		
		
		
		//定义页面级别的变量

		/**
		name:bizData#onBeforeNew
		description: <b>[回调型事件]</b>业务数据新增前
		@param {object} event 它的结构如下:<br/>{"source":组件的js对象,"cancel":可修改，设置为true后中断当前new动作}
		 */
		Model.dataBillSettingBeforeNew = function(event) {

		};
		/**
		 * name:bizData#onAfterNew description: <b>[回调型事件]</b>业务数据新增后
		 * 
		 * @param event
		 *            它的结构如下:<br/>{"source":组件的js对象,"id":新增的行Id}
		 */
		Model.dataBillSettingAfterNew = function(event){
			
		}

	    //接受参数
		Model.params = $rootScope.$stateParams;  
//		console.log('Model.params-->',Model.params);
		
		var options = {};
		options.container = Model;
		options.concept = 'BillSetting';
		options.name = 'dataBillSetting';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
		options.creater = '/backcenter/billSetting/list/create';
		options.reader = '/backcenter/billSetting/list/query';
		options.writer = '/backcenter/billSetting/list/save';
		options.deleter = '/backcenter/billSetting/list/delete';
		options.idColumnDefine = "fID";
		options.idColumnName = "fID";
		options.defCols = {fID:{name:"fID",type:"String",label:""},appId:{name:"appId",type:"String",label:""},appName:{name:"appName",type:"String",label:""},billType:{name:"billType",type:"String",label:""},billTypeName:{name:"billTypeName",type:"String",label:""},preChar:{name:"preChar",type:"String",label:""},codeType:{name:"codeType",type:"String",label:""},codeCount:{name:"codeCount",type:"Integer",label:""},autoCode:{name:"autoCode",type:"String",label:""},direction:{name:"direction",type:"Integer",label:""},costingCode:{name:"costingCode",type:"String",label:""},revOpay:{name:"revOpay",type:"String",label:""},revOpayLabel:{name:"revOpayLabel",type:"String",label:""},origin:{name:"origin",type:"String",label:""},flowType:{name:"flowType",type:"Integer",label:""},originName:{name:"originName",type:"String",label:""},fMasterID:{name:"fMasterID",type:"String",label:""},codeTypeLabel:{name:"codeTypeLabel",type:"String",label:""},autoCodeLabel:{name:"autoCodeLabel",type:"String",label:""},directionLabel:{name:"directionLabel",type:"String",label:""},costingCodeLabel:{name:"costingCodeLabel",type:"String",label:""},flowTypeLabel:{name:"flowTypeLabel",type:"String",label:""},windowUrl:{name:"windowUrl",type:"String",label:""},windowProcess:{name:"windowProcess",type:"String",label:""},windowActivity:{name:"windowActivity",type:"String",label:""},version:{name:"version",type:"Integer",label:""}};
		options.isTree = false;
		options.parentRelation = 'sParent';
		options.nodeKindRelation = 'sNodeKind';
		options.nodeLevelRelation = 'sLevel';
		options.pathRelation = 'sFID';
		options.directDeleteMode = true;
		options.limit = 10;
		
		options.onIndexChanging = null;
		options.onIndexChanged = Model.dataBillSettingIndexChanged;
		options.onBeforeNew = Model.dataBillSettingBeforeNew;
		options.onAfterNew = Model.dataBillSettingAfterNew;
		options.onBeforeDelete = Model.dataBillSettingBeforeDelete;
		options.onAfterDelete = Model.dataBillSettingAfterDelete;
		options.onValueChanged = Model.dataBillSettingValueChanged;
		options.onDataChanged = Model.dataBillSettingDataChanged;
		
		$scope.dataBillSetting = new BizData(options);

		//监视对象中的所有变动
		$scope.dataBillSetting.deregRows = $scope.$watch('dataBillSetting.rows',$scope.dataBillSetting.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
		//////////////////////////////////////////////
		
		
		//增加过滤条件，只显示当前用户的
//		$scope.dataBillSetting.filter = "BillSetting.fMasterID='" + Model.params.id + "'";
		$scope.dataBillSetting.fMasterID = Model.params.id;
		
		Model.refresh = function(){
			$scope.dataBillSetting.refreshData();
		};
		
		
		Model.refresh();

		//添加(调用对话框)
		Model.add = function() {
			/*
			var to = '/backcenter/subsysBill/single';
			var params = {
					"id":$scope.dataBillSetting.fMasterID
					,"recordState":"new"
					};
			var options = {};
			$state.go(to,params,options);
			*/

			//打开对话框
			var options = {};
			
			options.recordState = 'new';
			options.id = Model.params.id;//$scope.dataBillSetting.fMasterID;
			options.appId = Model.params.appId;
			options.appName = Model.params.appName;

	        var modalInstance = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: $rootScope.getProjectName() + '/backcenter/billSetting/single',  
	            controller: 'billSettingSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '新建'; }
                    ,loadCtrl : $ocLazyLoad.load('js/billSetting/single')
		        }
	        });  
	        //模态窗口打开之后执行的函数
	        modalInstance.opened.then(function(){  
	        	
	        });  
	        //模态窗口关闭之后执行的事件
	        modalInstance.result.then(function (result) {  
	             //成功关闭窗口
	             $scope.dataBillSetting.refreshData();
	        }, function (reason) {  
	        });  
				
			
		};

		//修改
		Model.edit = function(row) {
			//打开对话框
//			var index = $scope.dataBillSetting.currentIndex;
//			var row = $scope.dataBillSetting.rows[index];
			if(!row){
				return;
			}

			var options = {};
			
			options.recordState = 'edit';
			options.id = row.fID.value;

	        var modalInstance = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: $rootScope.getProjectName() + '/backcenter/billSetting/single',  
	            controller: 'billSettingSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '修改'; }
                    ,loadCtrl : $ocLazyLoad.load('js/billSetting/single')
		        }
	        });  
	        //模态窗口打开之后执行的事件
	        modalInstance.opened.then(function(){
	        });  
	        //模态窗口关闭之后执行的事件
	        modalInstance.result.then(function (result) {  
	             //成功关闭窗口
	             $scope.dataBillSetting.refreshData();
//	             $scope.dataBillSetting.currentIndex = index;
	        }, function (reason) {  
	        });  
				
		};

		Model.remove = function(row) {
			if(!row){
				return;
			}
			
			//直接删除
			if($scope.dataBillSetting.deleteData(row.fID.value)==0){
				
			}
			
			Model.refresh();

		};

	    
	    ///////////////////////////页面级////////////////////////////////////////
		//返回
		$scope.goBack = function(event) {
			window.history.go(-1);
		}
	    ///////////////////////////页面级////////////////////////////////////////

		return Model;
		
	}    
    
//})



